<?php
/* Home controller 
** thaodx@gmail.com
*/
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
	// Layout used in this controller
    public $layout_view = 'layout/9gag';

	public function index($page = 0, $lastId = 0)
	{

		$page = intval($page);
		$lastId = intval($lastId);

		$this->load->model('Post_model', 'homeModel');
		$this->load->helper(array('datetime', 'permalink', 'social', 'image'));
		#$this->load->library('pagination');

		$latestPost = $this->homeModel->getLatestPost($page, HOME_LIMIT, $lastId);		
		$additionTitle = '';
		if($page > 0){
			$additionTitle = ' - Trang '. intval($page / CATE_LIMIT + 1);
		}
		$this->layout->title(SITE_TITLE . TITLE_SEPARATOR . 'Bài mới'.$additionTitle); // Set page title
		$this->layout->meta('<meta http-equiv="REFRESH" content="1800" />');
       	$data = array('data' => $latestPost, 'page' => $page);
       	$sidebar = $this->layout->renderBlock('block/home-side-bar');
       	$this->layout->sidebar($sidebar);
       	// paginate
       /*
       	$paging['base_url'] = BASE_URL.'/page/';
		$paging['total_rows'] = 4000;
		$paging['per_page'] = HOME_LIMIT;
		$paging['uri_segment'] = 2;
		$this->pagination->initialize($paging);

		$data['paging'] = $this->pagination->create_links();
		*/

       	$this->layout->view('home_index', $data);// Render view and layout
	}
}
